﻿using System;
using System.ServiceModel;
using MediaBrowserWS.Service.Enums;
using System.IO;
using MediaBrowserWS.Service.Classes;
using System.ServiceModel.Web;
using Microsoft.Ajax.Samples;
using System.Collections.Generic;

namespace MediaBrowserWS.Service
{
    // NOTE: If you change the interface name "IMediaBrowserService" here, you must also update the reference to "IMediaBrowserService" in Web.config.
    [ServiceContract]
    [ServiceKnownType(typeof(MetadataItem))]
    [ServiceKnownType(typeof(BasicCollectionItem))]
    public interface IMediaBrowserService
    {
        /// <summary>
        /// Retrieves an item from MediaBrowser given an Id, this is either a BasicItemCollection or MetadataItem depending on its type
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/item?id={id}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        BasicItem GetItem(Guid id);

        /// <summary>
        /// Gets the initial folders from the MediaBrowser startup screen
        /// </summary>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/startup", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        BasicCollectionItem GetStartUpFolders();

        /// <summary>
        /// Gets a collection/folder from the MediaBrowser library
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/collection?id={id}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        BasicCollectionItem GetCollection(Guid id);

        /// <summary>
        /// Retrieves an item from MediaBrowser given an Id, this is either a BasicItemCollection or MetadataItem depending on its type
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/metadata?id={id}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        MetadataItem GetMetadata(Guid id);

        /// <summary>
        /// Plays a specific item given its Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/play?id={id}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        bool PlayItem(Guid id);

        /// <summary>
        /// Gets an object representing what is currently playing in Media Center
        /// </summary>
        /// <param name="waitForUpdate"></param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/nowplaying?wait={waitForUpdate}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        NowPlayingItem GetNowPlaying(bool waitForUpdate);

        /// <summary>
        /// Retrieves an image for a particular item
        /// </summary>
        /// <param name="id">Id of the MediaItem</param>
        /// <param name="imageType">The type of image</param>
        /// <param name="maxHeight">O or int.MaxValue to ignore</param>
        /// <param name="maxWidth">O or int.MaxValue to ignore</param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/image?id={id}&imagetype={imageType}&maxheight={maxHeight}&maxwidth={maxWidth}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        PictureItem GetImage(Guid id, ImageTypes imageType, int maxHeight, int maxWidth);

        /// <summary>
        /// Sends a command for Media Center to perform
        /// </summary>
        /// <param name="command"></param>
        [OperationContract]
        [WebGet(UriTemplate="/command?type={command}")]
        [JSONPBehavior(callback = "method")]
        void SendCommand(CommandTypes command);

        /// <summary>
        /// Seeks to a specific time (in seconds) for the currently playing item
        /// </summary>
        /// <param name="seconds">Time in seconds</param>
        [OperationContract]
        [WebGet(UriTemplate = "/seek?duration={seconds}")]
        [JSONPBehavior(callback = "method")]
        void Seek(int seconds);

        /// <summary>
        /// Tells media Center to go to a specific screen
        /// </summary>
        /// <param name="screenType">The screen to go to</param>
        /// <param name="extraInfo">Any extra information for the screen in question</param>
        [OperationContract]
        [WebGet(UriTemplate = "/screen?type={screenType}&params={extraInfo}")]
        [JSONPBehavior(callback = "method")]
        void GoToScreen(ScreenType screenType, string extraInfo);

        /// <summary>
        /// Gets a list of available trailers and their source
        /// </summary>
        /// <param name="id">The id of the library to get trailers for</param>
        /// <returns></returns>
        [OperationContract]
        [WebGet(UriTemplate = "/trailers?id={id}", ResponseFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        TrailerInfo[] GetTrailers(Guid id);

        /// <summary>
        /// Plays a given library item on the host PC
        /// </summary>
        /// <param name="trailer"></param>
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/playtrailer", RequestFormat = WebMessageFormat.Json)]
        [JSONPBehavior(callback = "method")]
        void PlayTrailer(TrailerInfo trailer);
    }
}
